﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace PRE.Baocao
{
    public partial class FrmDanhsachduocnangluong : DevExpress.XtraEditors.XtraForm
    {
        #region Variable
        DAL.EntitiesDAL.DuocnangluongDAL _dal = new DAL.EntitiesDAL.DuocnangluongDAL();
        BLL.EntitiesBLL.DuocnangluongBLL _bll = new BLL.EntitiesBLL.DuocnangluongBLL();

        DataTable _dt = new DataTable();
        DataTable _dt1 = new DataTable();
        #endregion

        #region Inits
        public FrmDanhsachduocnangluong()
        {
            InitializeComponent();
        }
        #endregion

        #region PerformRefresh
        private void PerformRefresh()
        {
            LoadData();
        }
        #endregion

        #region load
        private void LoadData()
        {
            _dt = _dal.Select();
            _dt1 = _dal.Select_Nangluong();

            cbo_Nangluong.Properties.DataSource = _dt1;

            try
            {
                if (_dt != null)
                {
                    gridControl_Duocnangluong.DataSource = _dt;

                    AppGridView.SummaryField(gridView_Duocnangluong, "MANHANVIEN", "Tổng = {0:#,0} mẫu tin", DevExpress.Data.SummaryItemType.Count);

                    gridView_Duocnangluong.OptionsBehavior.ReadOnly = true;
                    gridView_Duocnangluong.OptionsView.ColumnAutoWidth = true;
                }


            }
            catch (Exception ex)
            {

                XtraMessageBox.Show("Lỗi! Không load được dữ liệu", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }
        #endregion

        #region Form load
       private void FrmDanhsachduocnangluong_Load(object sender, EventArgs e)
        {        
            PerformRefresh();
            bto_Loc.Visible = true;
            bto_In.Visible = true;
            bto_Thoat.Visible = true;
        }
        #endregion

        #region Thoát
       private void bto_Thoat_Click(object sender, EventArgs e)
       {
           this.Close();
       }
       #endregion

        #region Làm tươi
       private void bto_Lamtuoi_Click(object sender, EventArgs e)
       {
           FrmDanhsachduocnangluong_Load(null, null);
       }
       #endregion

        #region Lọc dữ liệu
       private void bto_Loc_Click(object sender, EventArgs e)
       {
           try
           {
               string Chonquyetdinh = Convert.ToString(cbo_Nangluong.EditValue);
               DataTable _dtSearch = _dal.Select_Danhsach_Nangluong(Chonquyetdinh);
               if (_dtSearch != null)
               {


                   gridControl_Duocnangluong.DataSource = _dtSearch;

                   AppGridView.SummaryField(gridView_Duocnangluong, "MANHANVIEN", "Tổng = {0:#,0} mẫu tin", DevExpress.Data.SummaryItemType.Count);

                   gridView_Duocnangluong.OptionsView.EnableAppearanceEvenRow = true;
                   gridView_Duocnangluong.OptionsView.ColumnAutoWidth = true;
               }
               gridControl_Duocnangluong.DataSource = _dtSearch;

               _dt = _dtSearch;
           }
           catch (Exception ex)
           {

               XtraMessageBox.Show("Lỗi! Không lọc được dữ liệu", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
           }
       }
       #endregion

        #region In dữ liệu
       private void bto_In_Click(object sender, EventArgs e)
       {
           string _NgayKy = "TP.Cần Thơ, ngày " + DateTime.Now.Day + " tháng " + DateTime.Now.Month + " năm " + DateTime.Now.Year;
           if (gridView_Duocnangluong.DataRowCount > 0)
           {
               DataTable dt = gridView_Duocnangluong.GetDataRow(0).Table.Clone();

               for (int i = 0; i < gridView_Duocnangluong.DataRowCount; i++)
               {
                   dt.ImportRow(gridView_Duocnangluong.GetDataRow(i));
               }
               Reports.FrmReportView frm = new Reports.FrmReportView();
               frm._load_XtraDuocnangluong(dt, _NgayKy);
               frm.Show();
           }
       }
       #endregion
    }
}
